mini.parse();
var projectName = $("#projectName").val();
var form = new mini.Form("form1");

function SaveData() {
	form.validate();
	if (form.isValid() == false)
		return;
	var json = GetData();
	CloseWindow(json);
}

////////////////////
//标准方法接口定义
function CheckEventSubTable(data) {
//跨页面传递的数据对象，克隆后才可以安全使用
	data = mini.clone(data);
	if (data.action == "edit") {
		SetData(data);
	} else if (data.action == "new") {
	}else if(data.action =="look"){
		SetData(data);
	}
}

function GetData(){
	var o = form.getData();
	return o;
}
function SetData(data){
	
}
function CloseWindow(action) {
	console.log(action);
	if (action == "close" && form.isChanged()) {
		if (confirm("数据被修改了，是否先保存？")) {
			return false;
		}
	}
	if (window.CloseOwnerWindow)
		return window.CloseOwnerWindow(action);
	else
		window.close();
}
function onOkSubTable(e) {
	SaveData();
}
function onCancelSubTable(e) {
	CloseWindow("cancel");
}

function labelModel() {
	var fields = form.getFields();
	for ( var i = 0, l = fields.length; i < l; i++) {
		var c = fields[i];
		if (c.setReadOnly)
			c.setReadOnly(true); //只读
		if (c.setIsValid)
			c.setIsValid(true); //去除错误提示
		if (c.addCls)
			c.addCls("asLabel"); //增加asLabel外观
	}
}
function inputModel() {
	var fields = form.getFields();
	for ( var i = 0, l = fields.length; i < l; i++) {
		var c = fields[i];
		if (c.setReadOnly)
			c.setReadOnly(false);
		if (c.removeCls)
			c.removeCls("asLabel");
	}
	mini.repaint(document.body);
}
function readOnlyForm(){
	$("#button_okSubTable").hide();
	$("#button_onSubTable").hide();
	form.setEnabled(false);
}
/////////////////////////////////////////////////////////////////////
/**物理仓页面**/
function onPhysicalStorageEdit(e){
	var orgId = mini.get("org_id").getValue();
    var btnEdit = this;
    mini.open({
        url: projectName+"/PhyStorageAdmin/phyStorageChoose",
        title:"物理逻辑仓选择", width: 780, height: 500,
        onload: function () {
            var iframe = this.getIFrameEl();
            var data = {orgId: orgId,chooseType:true};
            iframe.contentWindow.setData(data);
        },
        ondestroy: function (action) {
        	if (action == "ok") {
                var iframe = this.getIFrameEl();
                var data = iframe.contentWindow.GetData();
                data = mini.clone(data);
                var rows = data.rows;
                var ids = [], texts = [];
                for (var i = 0, l = rows.length; i < l; i++) {
                    var row = rows[i];
                    ids.push(row.physicalStorageId);
                    texts.push(row.physicalStorageName);
                }
                btnEdit.setValue(ids);
                btnEdit.setText(texts);
            }
        }
    });
}
/**逻辑仓页面**/
function onStorageEdit(){
	var physicalStorageId = mini.get("storage_addr_id").getValue();
    var btnEdit = this;
    mini.open({
        url: projectName+"/StStorageAdmin/stStorageChoose",
        title:"逻辑仓选择", width: 780, height: 500,
        onload: function () {
            var iframe = this.getIFrameEl();
            var data = {physicalStorageId: physicalStorageId};
            iframe.contentWindow.setData(data);
        },
        ondestroy: function (action) {
        	if (action == "ok") {
                var iframe = this.getIFrameEl();
                var data = iframe.contentWindow.GetData();
                data = mini.clone(data);
                btnEdit.setValue(data.id);
                btnEdit.setText(data.text);
            }
        }
    });
}
/**组织机构页面**/
function onOrgEdit(){
	mini.open({
		url:projectName+"/OrgAdmin/orgselect",
		title:'组织结构列表',width:700,height:500,
		onload:function(){
		    var iframe = this.getIFrameEl();
		    var action = {};
            iframe.contentWindow.CheckEventUser(action);
		},
		ondestroy:function ( action ){
			if(typeof(action)=="object"  && action.status==1){
				var data = mini.clone(rtdata);
				var textArray = [];
				var valueArray = [];
				for(var i=0; i<data.length; i++){
					valueArray.push(data[i].userNo);
					textArray.push(data[i].name);
				}
				mini.get("org_id").setValue(valueArray.join(","));
				mini.get("org_id").setText(textArray.join(","));
				mini.get("org_name").setValue(textArray.join(","));
			}
		}
		
	});
}
